import { View } from "../../../mvc/core/View";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { GTextFormat } from "../../../common/GTextFormat";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { Cache } from "../../cache/Cache";
import { MoneySelectPanel } from "./MoneySelectPanel";
import { EventName } from "../../mvc/EventName";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { MailFriendItemCellRender } from "../mail/MailFriendItemCellRender";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { DataEvent } from "../../events/DataEvent";
import { MsgManager } from "../../manager/MsgManager";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { TipsWindow } from "../player/TipsWindow";
import { Alert } from "../../../../com/mui/controls/Alert";
import { TextInput } from "../../../../fl/controls/TextInput";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { _code } from "../../../../this/_code";
import { _itemUid } from "../../../../this/_itemUid";
import { _amount } from "../../../../this/_amount";
import { _unit } from "../../../../this/_unit";
import { _time } from "../../../../this/_time";
type int = number;
//class SellMoneyPanel
    
    export  class SellMoneyPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ObjCreate.createBg(0, 0, 275, 265, this);
            var loc2=ObjCreate.createTextField(Language.getString(31064), 65, 20, 300, 25, this, new GTextFormat("", 16, 16776960));
            this._unit = EPrictUnit._EPriceUnitGold;
            this._code = EPrictUnit._EPriceUnitCoin;
            this._coinImg = GlobalClass.getBitmap(ImagesConst.Market_Coin);
            this._coinImg.x = 40;
            this._coinImg.y = 75;
            addChild(this._coinImg);
            this._goldImg = GlobalClass.getBitmap(ImagesConst.Market_Gold);
            this._goldImg.x = 40;
            this._goldImg.y = 75;
            this._goldImg.visible = false;
            addChild(this._goldImg);
            this._moneySellInput = ObjCreate.createGTextInput(100, 80, 80, 25, this);
            this._moneySellInput.restrict = "0-9";
            this._moneySellInput.maxChars = Cache.instance.market.MAX_NUMBER;
            this._moneySellInput.addEventListener(flash.events.Event.CHANGE, this.onMoneySellNumHandler);
            this._moneySelect = new MoneySelectPanel();
            this._moneySelect.x = 190;
            this._moneySelect.y = 65;
            this._moneySelect.setFirstSelected();
            addChild(this._moneySelect);
            this._moneySelect.addEventListener(EventName.MarketMoneyTypeChange, this.onMoneyTypeChangeHandler);
            var loc3=ObjCreate.createTextField(Language.getString(31051), 30, 140, 80, 20, this, GlobalStyle.textFormat2);
            var loc4=ObjCreate.createTextField(Language.getString(31053), 30, 180, 80, 20, this, GlobalStyle.textFormat2);
            var loc5=ObjCreate.createTextField(Language.getString(31054), 30, 215, 80, 20, this, GlobalStyle.textFormat2);
            this._priceInput = ObjCreate.createGTextInput(100, 135, 80, 25, this);
            this._priceInput.restrict = "0-9";
            this._priceInput.maxChars = Cache.instance.market.MAX_NUMBER;
            this._priceInput.addEventListener(flash.events.Event.CHANGE, this.onPriceInputHandler);
            this._coinIcon = GlobalClass.getBitmap(ImagesConst.Tongqian);
            this._coinIcon.x = 190;
            this._coinIcon.y = 140;
            this._coinIcon.visible = false;
            addChild(this._coinIcon);
            this._goldIcon = GlobalClass.getBitmap(ImagesConst.Yuanbao);
            this._goldIcon.x = 190;
            this._goldIcon.y = 140;
            addChild(this._goldIcon);
            this._feeNumTxt = ObjCreate.createTextField("", 100, 180, 150, 20, this, GlobalStyle.textFormat1);
            var loc6;
            (loc6 = new DataProvider()).addItem({"id": 8, "label": Language.getString(31056), "index": 0});
            loc6.addItem({"id": 24, "label": Language.getString(31057), "index": 1});
            loc6.addItem({"id": 48, "label": Language.getString(31058), "index": 2});
            this._timeCombo = this.createComboBox(100, 210, 100, 25, loc6);
            this._timeCombo.addEventListener(flash.events.Event.CHANGE, this.onTimeComboChangeHandler);
            this._broadcastCb = ObjCreate.createCheckBox(Language.getString(31123), 5, 265, 200, 40, this);
            var loc7;
            (loc7 = ObjCreate.createGButton(Language.getString(31055), 130, 272, 55, 25, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onSellBtnClickHandler);
            var loc8;
            (loc8 = ObjCreate.createGButton(Language.getString(31010), 200, 272, 55, 25, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onResetBtnClickHandler);
            return;
        }

        /* internal  */createComboBox(arg1: int, arg2: int, arg3: int, arg4: int, arg5: DataProvider): GComboBox
        {
            var loc1;
            (loc1 = new GComboBox()).selectedIndex = 0;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.move(arg1, arg2);
            loc1.styleName = "GComboboxStyle";
            loc1.drawNow();
            loc1.dropdown.setStyle("cellRenderer", MailFriendItemCellRender);
            loc1.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            loc1.textField.setStyle("textFormat", new GTextFormat("", 12, 11661308, false, false, false, "", "", flash.text.TextFormatAlign.CENTER));
            loc1.dataProvider = arg5;
            addChild(loc1);
            return loc1;
        }

        /* internal  */onMoneySellNumHandler(arg1: Object /* flash.events.Event */): void
        {
            this._amount = parseInt(this._moneySellInput.text);
            this.onPriceInputHandler();
            return;
        }

        /* internal  */onMoneyTypeChangeHandler(arg1: DataEvent): void
        {
            this._code = arg1.data as int;
            if (this._code != EPrictUnit._EPriceUnitCoin) 
            {
                this._unit = EPrictUnit._EPriceUnitCoin;
                this._coinIcon.visible = true;
                this._goldIcon.visible = false;
                this._coinImg.visible = false;
                this._goldImg.visible = true;
            }
            else 
            {
                this._unit = EPrictUnit._EPriceUnitGold;
                this._coinIcon.visible = false;
                this._goldIcon.visible = true;
                this._coinImg.visible = true;
                this._goldImg.visible = false;
            }
            this.onPriceInputHandler();
            return;
        }

        /* internal  */onPriceInputHandler(arg1: Object /* flash.events.Event */=null): void
        {
            var loc1=NaN;
            if (this._moneySellInput.text == "" || this._priceInput.text == "") 
            {
                return;
            }
            if (this._time != 8) 
            {
                if (this._time != 24) 
                {
                    if (this._time == 48) 
                    {
                        loc1 = 0.05;
                    }
                }
                else 
                {
                    loc1 = 0.03;
                }
            }
            else 
            {
                loc1 = 0.02;
            }
            var loc2=parseInt(this._priceInput.text);
            if (this._unit == EPrictUnit._EPriceUnitGold) 
            {
                loc2 = loc2 * 1000;
            }
            this._feeNumTxt.text = Math.ceil(loc2 * loc1) + " " + Language.getString(31036);
            return;
        }

        /* internal  */onTimeComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._time = this._timeCombo.selectedItem.id;
            this.onPriceInputHandler();
            return;
        }

        /* internal  */onSellBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc5=null;
            var loc6=null;
            if (this._moneySellInput.text == "") 
            {
                MsgManager.showRollTipsMsg(Language.getString(31065));
                return;
            }
            if (this._unit < 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(31066));
                return;
            }
            if (this._priceInput.text == "") 
            {
                MsgManager.showRollTipsMsg(Language.getString(31061));
                return;
            }
            if (parseInt(this._moneySellInput.text) <= 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(31067));
                return;
            }
            if (parseInt(this._priceInput.text) <= 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(31062));
                return;
            }
            var loc1="";
            var loc2="";
            var loc3="";
            var loc4="";
            if (this._unit != EPrictUnit._EPriceUnitCoin) 
            {
                loc1 = this._priceInput.text + Language.getString(31037);
                loc2 = Language.getString(31036);
                loc3 = ImagesConst.Yuanbao_small;
                loc4 = "MarketGoldSellMoney";
            }
            else 
            {
                loc1 = this._priceInput.text + Language.getString(31036);
                loc2 = Language.getString(31037);
                loc3 = ImagesConst.Tongqian_small;
                loc4 = "MarketCoinSellMoney";
            }
            if (PulseSharedObject.isTodayNotTips(loc4)) 
            {
                loc5 = {"code": _code, "itemUid": _itemUid, "amount": _amount, "price": parseInt(this._priceInput.text), "unit": _unit, "time": _time, "broadcast": this._broadcastCb.selected};
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarketGotoSell, loc5));
            }
            else 
            {
                loc6 = Language.getStringByParam(31068, this._amount, loc2, loc1);
                TipsWindow.instance.show();
                TipsWindow.instance.updateInfo(loc6, loc4, "", this.sureToSell);
                TipsWindow.instance.createImgAndName(loc3, Language.getString(31124));
            }
            return;
        }

        /* internal  */sureToSell(): void
        {
            var loc1={"code": _code, "itemUid": _itemUid, "amount": _amount, "price": parseInt(this._priceInput.text), "unit": _unit, "time": _time, "broadcast": this._broadcastCb.selected};
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketGotoSell, loc1));
            return;
        }

        /* internal  */onClickHandler(arg1: int, arg2: Boolean): void
        {
            var loc1=null;
            if (arg1 == Alert.OK) 
            {
                loc1 = {"code": _code, "itemUid": _itemUid, "amount": _amount, "price": parseInt(this._priceInput.text), "unit": _unit, "time": _time, "broadcast": this._broadcastCb.selected};
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarketGotoSell, loc1));
            }
            if (arg2) 
            {
                PulseSharedObject.save("MarketSellMoney", true);
            }
            return;
        }

        /* internal  */onResetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.resetPanel();
            return;
        }

        public resetPanel(): void
        {
            this._moneySellInput.text = "";
            this._priceInput.text = "";
            this._feeNumTxt.text = "";
            this._timeCombo.selectedIndex = 0;
            this._moneySelect.setFirstSelected();
            this._time = 8;
            this._unit = EPrictUnit._EPriceUnitGold;
            this._code = EPrictUnit._EPriceUnitCoin;
            this._coinIcon.visible = false;
            this._goldIcon.visible = true;
            this._coinImg.visible = true;
            this._goldImg.visible = false;
            return;
        }

        /* internal */ /* var */_priceInput: TextInput;

        /* internal */ /* var */_feeNumTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_timeCombo: GComboBox;

        /* internal */ /* var */_moneySelect: MoneySelectPanel;

        /* internal */ /* var */_moneySellInput: TextInput;

        /* internal */ /* var */_time: int=8;

        /* internal */ /* var */_unit: int=2;

        /* internal */ /* var */_amount: int;

        /* internal */ /* var */_itemUid: string="";

        /* internal */ /* var */_code: int=0;

        /* internal */ /* var */_coinImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_goldImg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_coinIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_goldIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_broadcastCb: GCheckBox;
    }
